<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>企业管理</title>
    <base href="${rc.contextPath}/">

    <#include "/commons/stylesheets.ftl">
    <!-- Data Tables -->
    <link href="bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <style type="text/css">
        #toolbar button {
            margin-right: 10px;
        }
        span.field {
            font-weight: bold;
            padding-right: 10px;
        }
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>企业管理 <small>列表</small></h5>

                    </div>
                    <div class="ibox-content">
                        <form id="form" class="form-inline">
                            <div class="form-group">
                                <label class="control-label">名称：</label>
                                <input type="text" placeholder="" name="companyName" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label">联系人：</label>
                                <input type="text" placeholder="" name="contactName" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label">类型：</label>
                                <select name="companyType" class="form-control" >
                                    <option value="">所有</option>
                                    <option value="1">银行</option>
                                    <option value="2">4S店</option>
                                    <option value="3">保险公司</option>
                                    <option value="4">修理厂</option>
                                    <option value="5">汽配厂商</option>
                                    <option value="6">其他</option>
                                </select>
                            </div>
                            <button class="btn btn-primary" type="button" style="margin-left: 20px;" onclick="search()"><i class="fa fa-search"></i>搜索</button>
                            <button class="btn btn-primary" type="button" style="margin-left: 20px;" onclick="add()"><i class="fa fa-edit"></i>新建</button>
                        </form>

                    <div id="toolbar">

                    </div>
                        <table id="table"
                               data-detail-view="false"
                               data-query-params="queryParams"
                               data-detail-formatter="showDetail"
                               data-striped="true"
                               data-icons-prefix="fa"
                               data-toolbar="#toolbar"
                               data-data-field="list"
                               data-search="false"
                               data-show-refresh="false"
                               data-show-columns="false"
                               data-show-export="false"
                               data-side-pagination="server"
                               data-pagination="true"
                               data-page-size="15"
                               data-page-list="[10,15,20,30]"
                               data-url="${rc.contextPath}/company/search"
                               >
                            <thead>
                                <tr>
                                    <th data-checkbox="true">id</th>
                                    <th data-field="companyName">企业名称</th>
                                    <th data-field="companyType" data-formatter="formatCompanyType">类型</th>
                                    <th data-field="organizationId" data-formatter="formatOrganization">区域</th>
                                    <th data-field="contactPerson1Name">联系人</th>
                                    <th data-field="contactPerson1Position">职位</th>
                                    <th data-field="contactPerson1Phone">电话</th>
                                    <th data-field="address">地址</th>
                                    <th data-field="id"  data-formatter="formatOperation">操作</th>
                                </tr>
                            </thead>
                            <tbody>

                            </tbody>

                        </table>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script id="operation" type="text/html">
        <a href="javascript:edit(<%=id%>)">编辑</a>
        <a href="javascript:del(<%=id%>)">删除</a>
    </script>
    <script id="userInfo" type="text/html">
        <fieldset>
            <legend>联系人1</legend>
            <span class="field">姓名</span><span class="value"><%=contactPerson1Name%></span><br/>
            <span class="field">电话</span><span class="value"><%=contactPerson1Phone%></span><br/>
            <span class="field">职位</span><span class="value"><%=contactPerson1Position%></span><br/>
        </fieldset>
        <fieldset>
            <legend>联系人2</legend>
            <span class="field">姓名</span><span class="value"><%=contactPerson2Name%></span><br/>
            <span class="field">电话</span><span class="value"><%=contactPerson2Phone%></span><br/>
            <span class="field">职位</span><span class="value"><%=contactPerson2Position%></span><br/>
        </fieldset>
    </script>
    <!-- 全局js -->
    <#include "/commons/scripts.ftl">

    <script src="layer/layer.js"></script>
    <script src="js/app.js"></script>
    <script src="js/template-native.js"></script>



    <script type="text/javascript" src="bootstrap-table/bootstrap-table.min.js"></script>
    <script type="text/javascript" src="bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>



    <!-- Page-Level Scripts -->
    <script>
       $(function(){$("#table").bootstrapTable({locale:'zh-CN'})});

    </script>

    <script type="text/javascript">
        var CompanyType = {"1":"银行","2":"4S店","3":"保险公司","4":"修理厂","5":"汽配厂商","6":"其他"};
        function search(){
            $("#table").bootstrapTable("refresh",{url:"${rc.contextPath}/company/search?"+$("#form").serialize()});
        }

        function add(){
            openDialog('company/create','新建企业',460,620);
        }

        function edit(id){

            openDialog('company/edit?id='+id,'修改企业信息',460,620);
        }

        function del(id){
            var handleResponse = function(resp){
                if (resp.resultCode == "success") {
                    refreshTable();
                    layer.msg('删除成功');
                } else {
                    layer.msg('删除失败');
                }
            };
            layer.confirm('确定要删除选择的记录吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                           url:"company/delete",traditional:true,data:{ids:id},type:'post',success:handleResponse
                       });
                layer.closeAll();
            });


        }

        var Organizations={};
        function initOrganization(){
            $.getJSON("company/queryOrganization", function (list) {
                var parent;
                for (var i = 0; i < list.length; i++) {
                    row = list[i];
                    Organizations[row.organizationId] = row.name;
                }
            });
        }
        function pageInit(){
            initOrganization();
        }

        function showDetail(index,row){
            return template("userInfo", row)
        }

        function formatCompanyType(value,row,index){
            return CompanyType[value]
        }

        function formatOperation(value,row,index){
            return template("operation", row)
        }

        function formatOrganization(value,row,index){
            return Organizations[value]
        }

        function refreshTable(){
            $("#table").bootstrapTable("refresh");
        }

        function queryParams(params){
            return params;
        }
    </script>


    <!--统计代码，可删除-->

</body>

</html>